iT邦幫忙

2023 iThome 鐵人賽

DAY 18
0
Modern Web

30天前端學習筆記心得系列 第 18

Day18-Justify-content和Align-items

  • 分享至 

  • xImage
  •  

Justify-content水平對齊

指定彈性容器項目在主軸上對齊方式,主軸是水平方向

flex-start

從左側或頂部開始對齊

.container {
    display: flex;
    justify-content: flex-start;

https://ithelp.ithome.com.tw/upload/images/20231003/20163257WEZxgjRGlu.png

flex-end

從右側或底部開始對齊

.container {
  display: flex;
  justify-content: flex-end;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257XvotiEeeUJ.png

center

項目居中對齊

.container {
  display: flex;
  justify-content: center;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257Y5X1j1UuIz.png

space-between

項目之間均勻分配空白

.container {
  display: flex;
  justify-content: space-between;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257MAc7UlZKQT.png

space-around

項目周圍均勻分配空白

.container {
  display: flex;
  justify-content: space-around;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257VxooGS4EMC.png

space-evenly

項目之間和項目周圍均勻分配空白

.container {
  display: flex;
  justify-content: space-evenly;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257Nzwy1eQB0R.png

Align-items垂直對齊

指定彈性容器項目在交叉軸上對齊方式,交叉軸是與主軸垂直的軸

flex-start

項目從交叉軸起點開始對齊

.container {
  display: flex;
  align-items: flex-start;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257pAn0oLkCPR.png

flex-end

項目從交叉軸終點開始對齊

.container {
  display: flex;
  align-items: flex-end;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257cWK7dBQoNG.png

center

項目在交叉軸上居中對齊

.container {
  display: flex;
  align-items: center;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257by49vmvMec.png

stretch

項目在交叉軸上拉伸填滿容器高度或寬度

.container {
  display: flex;
  align-items: stretch;
}

https://ithelp.ithome.com.tw/upload/images/20231003/201632575yRuzcZAiM.png

baseline

項目基線對齊

.container {
  display: flex;
  align-items: baseline;
}

https://ithelp.ithome.com.tw/upload/images/20231003/20163257QZ79ECWrlx.png

資料來源:深入解析 CSS Flexbox
Flex 基礎教學


上一篇
Day17-CSS FLEXBOX
下一篇
Day18-Align-Self和Align-Content
系列文
30天前端學習筆記心得34
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言